const path = require('path');
const webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var precss = require('precss');
var autoprefixer = require('autoprefixer');

module.exports = {
  entry: {
    app: [path.resolve(__dirname, '../src/scripts/app.coffee')],
    vendors: [
      'angular',
      'jquery',
      'lodash',
      'bootstrap/dist/css/bootstrap.css',
      'bootstrap/dist/fonts/glyphicons-halflings-regular.eot',
      'bootstrap/dist/fonts/glyphicons-halflings-regular.svg',
      'bootstrap/dist/fonts/glyphicons-halflings-regular.ttf',
      'bootstrap/dist/fonts/glyphicons-halflings-regular.woff',
      'bootstrap/dist/fonts/glyphicons-halflings-regular.woff2'
    ]
  },
  output: {
    path: path.resolve(__dirname, '../build'),
    filename: 'bundle.js'
  },
  module: {
    loaders: [{
      test: /\.coffee$/,
      loader: 'coffee'
    },{
      test: /\.jade$/,
      loader: 'jade'
    },{
      test: /\.sass$/,
      loader: 'style!css!postcss!sass'
    },{
      test: /\.css$/,
      loader: 'style!css'
    },{
      test: /\.(png|jpg|jpeg|gif)$/,
      loader: 'url?limit=25000'
    },{
      test: /\.(woff|woff2|eot|ttf|svg)\??.*$/,
      loader: 'url?limit=100000'
    },{
      test: /\.json$/,
      loader: 'json'
    }]
  },
  postcss: function() {return [precss, autoprefixer];},
  plugins: [
    new HtmlWebpackPlugin({
      template: path.resolve(__dirname, '../src/index.jade'),
      favicon: path.resolve(__dirname, '../favicon.ico')
    }),
    new webpack.ProvidePlugin({
      $: "jquery",
      jQuery: "jquery",
      "window.jQuery": "jquery"
    }),
    new webpack.optimize.CommonsChunkPlugin('vendors', 'vendors.js')
  ],
  resolve: {
    alias: {
      constant: path.resolve(__dirname, '../src/libs/scripts/configs/constant.coffee'),
      statusFilter: path.resolve(__dirname, '../src/libs/scripts/filters/status.coffee'),
      commonFilter: path.resolve(__dirname, '../src/libs/scripts/filters/common.coffee'),
      currencyDirective: path.resolve(__dirname, '../src/libs/scripts/directives/currency.coffee'),
      datetimepicker: path.resolve(__dirname, '../src/libs/scripts/directives/datetimepicker.coffee'),
      yhPermissionDirective: path.resolve(__dirname, '../src/libs/scripts/directives/yh-permission.coffee'),
      angularValidationSupportDirective: path.resolve(__dirname, '../src/libs/scripts/directives/angular-validation-support.coffee'),
      interceptor: path.resolve(__dirname, '../src/libs/scripts/interceptors/interceptor.coffee'),
      authEvents: path.resolve(__dirname, '../src/libs/scripts/authorizations/auth-events.coffee'),
      commonService: path.resolve(__dirname, '../src/libs/scripts/utils/common.coffee'),
      sessionService: path.resolve(__dirname, '../src/libs/scripts/utils/session.coffee'),
      dialogService: path.resolve(__dirname, '../src/libs/scripts/utils/dialog.coffee'),
      ztreeService: path.resolve(__dirname, '../src/libs/scripts/utils/ztree.coffee'),

      baseService: path.resolve(__dirname, '../src/scripts/services/base.service.coffee'),
      accountService: path.resolve(__dirname, '../src/scripts/services/account.service.coffee'),
      messagePushService: path.resolve(__dirname, '../src/scripts/services/messagePush.service.coffee'),

      'angucomplete-alt': path.resolve(__dirname, '../src/libs/scripts/vendors/angucomplete-alt/angucomplete-alt.coffee'),
      'angucomplete-alt-css': path.resolve(__dirname, '../src/libs/scripts/vendors/angucomplete-alt/angucomplete-alt.css'),
      'angularPrint': path.resolve(__dirname, '../src/libs/scripts/vendors/angularPrint/angularPrint.js'),
      'angularPrint-css': path.resolve(__dirname, '../src/libs/scripts/vendors/angularPrint/angularPrint.css'),
      'datetimepicker-css': path.resolve(__dirname, '../node_modules/eonasdan-bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.css'),

      'datetimepickerCss': path.resolve(__dirname, '../src/libs/scripts/datetimepicker/bootstrap-datetimepicker.css'),
      'datetimepickerJs': path.resolve(__dirname, '../src/libs/scripts/datetimepicker/bootstrap-datetimepicker.js'),


      'ng-table-css': path.resolve(__dirname, '../node_modules/ng-table/dist/ng-table.css'),
      'ztree-css': path.resolve(__dirname, '../node_modules/ztree/css/zTreeStyle/zTreeStyle.css'),
      'ng-dialog-css': path.resolve(__dirname, '../node_modules/ng-dialog/css/ngDialog.css'),
      'quill-base-css': path.resolve(__dirname, '../node_modules/quill/dist/quill.base.css'),
      'quill-snow-css': path.resolve(__dirname, '../node_modules/quill/dist/quill.snow.css'),
      'select2-css': path.resolve(__dirname, '../node_modules/select2/dist/css/select2.css'),
      'angular-tooltips-css': path.resolve(__dirname, '../node_modules/angular-tooltips/dist/angular-tooltips.css'),
      'datepicker-css': path.resolve(__dirname, '../node_modules/bootstrap-datepicker/dist/css/bootstrap-datepicker.css'),
      'datepicker3-css': path.resolve(__dirname, '../node_modules/bootstrap-datepicker/dist/css/bootstrap-datepicker3.css'),
      'ng-dialog-theme-default-css': path.resolve(__dirname, '../node_modules/ng-dialog/css/ngDialog-theme-default.css'),
      'qiniu-js': path.resolve(__dirname, '../node_modules/qiniu-js/dist/qiniu.js'),
      'select2': path.resolve(__dirname, '../node_modules/select2/dist/js/select2.full.js'),
      'ng-quill': path.resolve(__dirname, '../node_modules/ng-quill/src/ng-quill.js'),
      'angular-validation-rule': path.resolve(__dirname, '../node_modules/angular-validation/dist/angular-validation-rule.js')
    }
  }
};